﻿using System;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Framework.MVC;
using Collection.IService.Entry;
using CollectionCenter.Models;
using System.Collections.Generic;
using CollectionCenter.Expand;

namespace CollectionCenter.Controllers
{
    public class MarkController : AsyncControllerBase
    {

        #region New

        public void NewAsync(string code) {
            NewMarkModel model = new NewMarkModel { 
                MarkIndate = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"),
                MarkSource = Request.UserHostAddress,
                MarkSourceCode = code
            };
            InitModel(model);

            this.InitConfig<IDictionary<string, string>>("mvc:redirect:mark:new", (controller, dictionary) =>
            {
                ViewBag.Redirect = dictionary;
            });
            
        }

        public ActionResult NewCompleted(MarkEntry entry) {
            IDictionary<string, string> dictionary = ViewBag.Redirect;
            return Redirect(entry == null?dictionary["error"]:string.Format(dictionary.ContainsKey(entry.sourcecode) ? dictionary[entry.sourcecode] : dictionary["default"],entry.code));
        }

        #endregion New

    }
}
